<docs>
  ## 编辑工作经历
</docs>
<template>
  <div class="wrap">
    <my-bread title="工作经历"></my-bread>
    <co-form :model="data" :rules="rules" ref="form">
      <co-input prop="dwmc" label="单位名称" v-model="data.dwmc" placeholder="请输入单位名称"></co-input>
      <data-picker1 prop="jzkssj" label="就职开始时间" v-model="data.jzkssj"></data-picker1>
      <data-picker1 prop="jzjzsj" label="就职截止时间" v-model="data.jzjzsj"></data-picker1>
      <co-input prop="jygw" label="工作岗位" v-model="data.jygw" placeholder="请输入工作岗位"></co-input>
      <co-input prop="gzsm" label="工作职责及取得成绩" v-model="data.gzsm" placeholder="请输入工作职责及取得成绩"></co-input>
    </co-form>
    <div class="btn-wrap">
      <button class="weui-btn weui-btn_primary" @click="save(0)" type="button">保存</button>
    </div>
  </div>
</template>
<script>
import $ from "@/common/js/axios";
import { validator } from "common/js/valid";
import store from "@/store/index";
import coForm from "base/form/form";
import coInput from "base/form/input";
import coSelect from "base/form/select";
import coLevelPicker from "base/form/levelPicker";
// import dataPicker1 from "base/form/dataPicker1";
import dataPicker1 from "base/form/dataPicker3";

export default {
  name: "editWork",
  components: { coForm, coInput, coSelect, coLevelPicker, dataPicker1 },
  data() {
    return {
      show: false,
      data: {
        grqzid: "",
        gzjlid: "",
        jzjzsj: "", // 就职截止时间
        jzkssj: "", // 就职开始时间
        dwmc: "", // 单位名称
        jygw: "", // 岗位
        gzsm: "", // 工作职责及取得成绩及取得成绩
        ywcz: "" // 业务操作，（1：新增，2：修改，0：删除）
      },
      rules: {
        jzjzsj: validator('11,"full","就职截止时间",false'), // 就职截止时间
        jzkssj: validator('48,full,"就职开始时间",false'), // 就职开始时间
        dwmc: validator('64,"full","单位名称",false'), // 单位名称
        // dwdd: validator('32,"full","工作地点",false'), // 工作地点
        jygw: validator('64,"full","工作岗位",false'), // 岗位
        gzsm: validator('168,"full","工作职责及取得成绩",true'), // 描述
        // xc: validator('9,"number","薪酬",false') // 薪资
      },
      gzdd_xs: "",
      obj: {
        grqzid: "",
        ywcz: "1"
      }
    };
  },
  methods: {
    save(next) {
      this.$refs.form.validate(() => {
        this.POST_save(next);
      });
    },
    /* 保存基本信息修改 */
    POST_save(next) {
      this.$confirm("确定保存？", "提示")
        .then(() => {
          this.$loading = true;
          this.$http
            .post("/grgl/gzjlBc", this.data)
            .then(res => {
              const resData = res.returnData;
              this.$alert(resData.message, () => {
                const code = +resData.executeResult;
                if (code && next) {
                  this.obj.yyjnlx = "40"; //教育经历跳转
                  this.$router.push({
                    name: "UserResumeeditSchoolExper",
                    query: this.obj
                  });
                } else if (code) {
                  // this.$router.push({ name: "userResume" });
                  this.$router.go(-1);
                }
              });
            })
            .finally(() => {
              this.$loading = false;
            });
        })
        .catch(() => {
          this.$toast("选择了取消");
        });
    }
  },
  created() {
    var gzjl = this.$route.query;
    Object.keys(this.data).forEach(item => {
      this.data[item] = gzjl[item];
    });
    Object.keys(this.obj).forEach(item => {
      this.obj[item] = gzjl[item];
    });
    this.data.dwdd = gzjl.gzdd;
    this.data.jygw = gzjl.gzgw;
    // 行政区划显示
    this.gzdd_xs = gzjl.gzdd_xs;
  }
};
</script>
<style scoped lang="scss">
@import "~common/scss/var.scss";
.wrap {
  .btn-wrap {
    display: flex;
    .weui-btn {
      margin: 0 auto;
      flex: 0 1 60%;
      margin-top: $margin-base;
    }
  }
  .tip {
    padding: $margin-base;
    font-size: $font-size-small;
    color: $color-warning;
  }
}
</style>
